#!/bin/bash

source /home/shell/util.sh

while [ true ]; do
    curl -sL https://www.zentao.net/download.html|grep -Po "禅道\d{2}.*版本发布"|uniq|perl -pe "s/\D*(\d+\.\d+\.?\d?).*/\1/g"
    read -p "请选择版本：" version
    if [[ -z "${version}" ]]; then
        printFail "请输入版本"
    else
        break;
    fi
done

download /opt/ZenTaoPMS.tar.gz https://www.zentao.net/dl/zentao/${version}/ZenTaoPMS.${version}.zbox_64.tar.gz

tar -xf /opt/ZenTaoPMS.tar.gz -C /opt

rm -rf /opt/ZenTaoPMS.tar.gz

read -p "web访问端口[80]：" http_port
http_port=${http_port:-"80"};

read -p "mysql端口[3306]：" mysqlserver_port
mysqlserver_port=${mysqlserver_port:-"3306"};

/opt/zbox/zbox -ap ${http_port} -mp ${mysqlserver_port}
# 创建服务
bash /home/shell/serviced-install.sh<<EOF
2
1

zentao
/opt/zbox/zbox start


/opt/zbox/zbox stop

EOF

firewall-addport ${http_port}

printInfo "======================zentao======================"
printInfo "adminer添加用户：/opt/zbox/auth/adduser.sh"
printInfo "数据库：zentao"
printInfo "数据库用户名：root"
printInfo "数据库密码：123456"
printInfo "数据库端口：${mysqlserver_port}"
printInfo "禅道用户名：admin"
printInfo "禅道密码：123456"
printInfo "访问地址：http://$host_addr:$http_port"
printInfo "======================zentao======================"